package org.microframework.base.feign.system;

import org.microframework.base.core.constant.ServiceNameConstants;

import org.microframework.base.core.constant.SecurityConstants;
import org.microframework.base.core.domain.R;
import org.microframework.base.feign.system.factory.RemoteUserFallbackFactory;
import org.microframework.base.model.system.domain.User;
import org.microframework.base.model.system.dto.SecurityUser;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;

/**
 * 用户服务
 * 
 */
@FeignClient(contextId = "remoteUserService", value = ServiceNameConstants.SYSTEM_SERVICE, fallbackFactory = RemoteUserFallbackFactory.class)
public interface RemoteUserService {
	/**
	 * 通过用户名查询用户信息
	 *
	 * @param username 用户名
	 * @param source   请求来源
	 * @return 结果
	 */
	@GetMapping("/user/info/{username}")
	public R<SecurityUser> getUserInfo(@PathVariable("username") String username,
			@RequestHeader(SecurityConstants.FROM_SOURCE) String source);
	/**
	 * 注册用户信息
	 *
	 * @param sysUser 用户信息
	 * @param source  请求来源
	 * @return 结果
	 */
	@PostMapping("/user/register")
	public R<Boolean> registerUserInfo(@RequestBody User sysUser,
			@RequestHeader(SecurityConstants.FROM_SOURCE) String source);

	/**
	 * 记录用户登录IP地址和登录时间
	 *
	 * @param sysUser 用户信息
	 * @param source  请求来源
	 * @return 结果
	 */
	@PutMapping("/user/recordlogin")
	public R<Boolean> recordUserLogin(@RequestBody User sysUser,
			@RequestHeader(SecurityConstants.FROM_SOURCE) String source);

	/**
	 * 通过用户名加载用户信息
	 *
	 * @param username 用户名
	 * @param source   请求来源
	 * @return 结果
	 */
	@GetMapping("/user/{username}")
	public R<SecurityUser> loadUserByUsername(@PathVariable("username") String username,
			@RequestHeader(SecurityConstants.FROM_SOURCE) String source);
	
}
